<?php defined('InNcPHP') or exit('Access Invalid!');?>

<script type="text/javascript" src="<?php echo RESOURCE_URL;?>/common/jquery-ui/jquery.ui.js"></script>
<script type="text/javascript" src="<?php echo RESOURCE_URL;?>/common/jquery-ui/i18n/zh-CN.js" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="<?php echo RESOURCE_URL;?>/common/jquery-ui/themes/ui-lightness/jquery.ui.css"  />

<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <h3><?php echo $lang['nc_manage'];?></h3>
            <?php echo $output['top_link'];?>
        </div>
    </div>
    <div class="fixed-empty"></div>
    <!--  搜索表单  -->
    <form method="get" name="formSearch" id="formSearch">
        <input type="hidden" value="merchant" name="act">
        <input type="hidden" value="index" name="op">
        <table class="tb-type1 noborder search">
            <tbody>
            <tr>
                <th><label> <?php echo $lang['merchant_shop_name'];?></label></th>
                <td><input type="text" name="search_shop_name" value="<?php echo $output['search']['search_shop_name']; ?>" class="txt"></td>
                <th><label><?php echo $lang['merchant_apply_time'];?></label></th>
                <td><input type="text" name="search_stime" id="search_stime" value="<?php echo $output['search']['search_stime']; ?>" class="txt date"></td>
                <td><input type="text" name="search_etime" id="search_etime" value="<?php echo $output['search']['search_etime']; ?>" class="txt date"></td>
                <th></th>
                <td>
                    <a href="javascript:void(0);" onclick="$('#formSearch').submit();" class="btn-search"></a>
                </td>
                <?php if ($output['search']['search_shop_name'] || $output['search']['search_stime'] || $output['search']['search_etime']): ?>
                <th></th>
                <td><a href="index.php?act=merchant&op=merchant" class="btns "><span><?php echo $lang['nc_cancel_search']?></span></a></td>
                <?php endif; ?>
            </tr>
            </tbody>
        </table>
    </form>

    <a class="m-btn blue-stripe mini <?php echo $_GET['search_status']==''?'checked':'' ?> " onclick="parent.openItem('index,merchant,member');" href="#">全部商家</a>
    <a class="m-btn green-stripe mini <?php echo $_GET['search_status']=='0'?'checked':'' ?>" onclick="parent.openItem('index,merchant,member,search_status=0');"  href="#">审核中</a>
    <a class="m-btn yellow-stripe mini <?php echo $_GET['search_status']==1?'checked':'' ?>" onclick="parent.openItem('index,merchant,member,search_status=1');"  href="#">审核通过</a>
    <a class="m-btn red-stripe mini  <?php echo $_GET['search_status']==2?'checked':'' ?> " onclick="parent.openItem('index,merchant,member,search_status=2');" href="#">审核失败</a>



    <!--  显示列表  -->
    <table class="table tb-type2 nobdb">
        <thead>
        <tr class="thead">
            <th><?php echo $lang['merchant_shop_name']?></th>
            <th><?php echo $lang['merchant_name']?></th>
            <th class="align-center"><?php echo $lang['merchant_phone']?></th>
            <th class="align-center"><?php echo $lang['merchant_lic']?></th>
            <th class="align-center"><?php echo $lang['merchant_idcard']?></th>
            <th class="align-center"><?php echo $lang['merchant_idcardb']?></th>
            <th class="align-center"><?php echo $lang['merchant_cate']; ?></th>
            <th class="align-center">提现费率</th>
            <th class="align-center"><?php echo $lang['merchant_apply_time']?></th>
            <th class="align-center"><?php echo $lang['merchant_state'];?></th>
           <!-- <th class="align-center"><?php /*echo '银行审核状态';*/?></th>-->
            <th class="align-center"><?php echo $lang['nc_handle'];?></th>
        </tr>
        <tbody>
        <?php if(!empty($output['merchant_list']) && is_array($output['merchant_list'])){ ?>
            <?php foreach($output['merchant_list'] as $k => $v){ ?>
                <tr class="hover member">
                    <td><?php echo $v['mc_shop_name']; ?></td>
                    <td><?php echo $v['mc_name']; ?></td>
                    <td class="align-center"><?php echo $v['mc_phone']; ?></td>
                    <td class="align-center">
                        <a data-src="<?php echo $v['mc_lic_img']; ?>" class="show-img" style="cursor:pointer;">[<?php echo $lang['merchant_show']; ?>]</a>
                    </td>
                    <td class="align-center">
                        <a data-src="<?php echo $v['mc_idcard_img']; ?>" class="show-img" style="cursor:pointer;">[<?php echo $lang['merchant_show']; ?>]</a>
                    </td>
                    <td class="align-center">
                        <a data-src="<?php echo $v['mc_idcardb_img']; ?>" class="show-img" style="cursor:pointer;">[<?php echo $lang['merchant_show']; ?>]</a>
                    </td>
                    <td class="align-center"><?php echo $v['mc_cate_name']; ?></td>
                    <td class="align-center"><?php echo $v['pd_tariff']>0?$v['pd_tariff'].'%':'0%'; ?></td>
                    <td class="align-center"><?php echo date('Y-m-d H:i:s',$v['mc_apply_time']); ?></td>
                    <td class="align-center"><?php echo $output['state'][$v['mc_status']]; ?></td>
                   <!-- <td class="align-center"><?php /*if(!empty($v['bank_status'])){echo $output['bank_state'][$v['bank_status']];}else{ echo '未进件';} */?></td>-->
                    <td class="align-center">
                        <?php if(!isset($output['merchant_id'])): ?>

                    <?php if ($v['mc_status'] == 0){?>
                        <a href="javascript:checkOk(<?php echo $v['merchant_id']; ?>);">审核通过</a> |
                        <a href="javascript:checkFail(<?php echo $v['merchant_id']; ?>);">审核失败</a>
                    <?php }elseif($v['mc_status'] ==1){?>
                       <?php if($v['is_disable']==0) {?>
                            <a href="javascript:off_merchant(<?php echo $v['merchant_id']; ?>);">禁用</a>
                       <?php  }else{?>
                            <a href="javascript:start_merchant(<?php echo $v['merchant_id']; ?>);">启用</a>
                        <?php } ?>
                       <?php }?>

                    <?php endif; ?>
                        <a href="index.php?act=merchant&op=edit&id=<?php echo $v['merchant_id']; ?>">编辑</a>
                    </td>
                </tr>
            <?php } ?>

        <?php }else { ?>
            <tr class="no_data">
                <td colspan="11"><?php echo $lang['nc_no_record']?></td>
            </tr>
        <?php } ?>
        </tbody>
        <tfoot class="tfoot">
        <?php if(!empty($output['merchant_list']) && is_array($output['merchant_list'])){ ?>
            <tr>
                <td colspan="16">
                    <div class="pagination"> <?php echo $output['page'];?> </div>
                </td>
            </tr>
        <?php } ?>
        </tfoot>
    </table>
</div>

<img id="show-img" style="display: none;max-width: 100%;max-height: 350px;position: relative;" src="http://image5.tuku.cn/pic/wallpaper/fengjing/daziranshenqishanshuifengjingbizhi/012.jpg">
<script>
    //开始日期
    $('#search_stime').datepicker({
        dateFormat: 'yy-mm-dd',
        onClose: function(selectedDate) {
            $("#search_etime").datepicker("option", "minDate", selectedDate);
        }
    });
    //结束日期
    $('#search_etime').datepicker({
        dateFormat: 'yy-mm-dd',
        onClose: function(selectedDate) {
            $("#search_stime").datepicker("option", "maxDate", selectedDate);
        }
    });

    //显示图片
    $('.show-img').click(function () {
        var src = $(this).data('src');
        layer.open({
            type: 1,
            title: false,
            content: $('#show-img').attr('src',src)
        });
    });

    //审核成功
    function checkOk(id) {
        layer.confirm('确认审核通过', {
            btn: ['<?php echo $lang['nc_yes']; ?>', '<?php echo $lang['nc_no']; ?>']
        }, function (index) {
            $.post('index.php?act=merchant&op=merchant_check', {mid:id,state:1},function (data) {
                if (data.errcode == 0) {
                    location.reload();
                }
            },'json');
            layer.close(index);
        });
    }

    //审核失败
    function checkFail(id) {
        layer.confirm('确认审核失败', {
            btn: ['<?php echo $lang['nc_yes']; ?>', '<?php echo $lang['nc_no']; ?>']
        }, function (index) {
            $.post('index.php?act=merchant&op=merchant_check', {mid:id,state:2},function (data) {
                if (data.errcode == 0) {
                    location.reload();
                }
            },'json');
            layer.close(index);
        });
    }

    //禁用商家
    function off_merchant(id){
        layer.confirm('是否禁用该商户?<br>(继续操作将导致该商户所有商品下架)',{
            btn: ['<?php echo $lang['nc_yes']; ?>', '<?php echo $lang['nc_no']; ?>']
        },function (index) {
            $.post('index.php?act=merchant&op=merchant_state',{mid:id,type:1},function(data){
                if (data.errcode == 0) {
                    location.reload();
                }
            },'json');
           layer.close(index);
        }
        );
    }

    //启用商家
    function start_merchant(id){
        layer.confirm('是否启用该商户?',{
                btn: ['<?php echo $lang['nc_yes']; ?>', '<?php echo $lang['nc_no']; ?>']
            },function (index) {
                $.post('index.php?act=merchant&op=merchant_state',{mid:id,type:2},function(data){
                    if (data.errcode == 0) {
                        location.reload();
                    }
                },'json');
                layer.close(index);
            }
        );
    }

</script>
